package com.xbongbong.parent.abstracts;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.ext.FieldPermissionEntityExt;
import com.xbongbong.paas.domain.entity.ext.OptionalRangeEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.EnableEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.VisibleTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.field.VisibleRulePoJo;
import com.xbongbong.paas.field.VisibleRuleVO;
import com.xbongbong.paas.help.CommonHelp;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.sys.help.PackageHelp;
import com.xbongbong.paas.help.ProFormHelp;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.enums.PackageTypeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.enums.teammembers.enums.FormOwnerUniqueEnum;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.pro.formexplain.pojo.vo.HandlerExplainVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.CompanyConfigEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.CostAdjustEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.product.CostAdjustProductEnum;
import com.xbongbong.saas.service.toolbox.help.UserTeamHelp;
import com.xbongbong.sys.domain.entity.CompanyConfigEntity;
import com.xbongbong.sys.domain.entity.DepartmentEntity;
import com.xbongbong.sys.domain.entity.RoleEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.model.CompanyConfigModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/11/2 9:57
 * @desrcption: 处理字段回显用户，角色，部门的问题
 */
@Component
public abstract class AbstractFormExplainHandleName {

    private static final Logger LOG = LoggerFactory.getLogger(AbstractFormExplainHandleName.class);

    @Resource
    private FormDataFormExplainHelper formDataFormExplainHelper;
    @Resource
    private ProFormHelp proFormHelp;
    @Resource
    private PackageHelp packageHelp;
    @Resource
    private UserTeamHelp userTeamHelp;
    @Resource
    private CommonHelp commonHelp;
    @Resource
    private CompanyConfigModel companyConfigModel;

    /**
     * 处理字段中的部门，角色，用户的名称，以及过滤不可见字段
     * @return
     * @throws XbbException
     */
    public abstract HandlerExplainVO handleExplain(HandlerExplainDTO handlerExplainDTO) throws XbbException;

    /**
     * 为图片字段和附件字段设置限制默认值
     * 图片上限为30MB
     * 附件开通过断点续传的白名单用户200MB非白名单50MB
     *
     * @param handlerExplainVO
     * @param handlerExplainDTO
     * @return handlerExplainVO
     */
    public HandlerExplainVO handleExplainDefaultLimit(HandlerExplainVO handlerExplainVO, HandlerExplainDTO handlerExplainDTO) {
        if (StringUtil.isEmpty(handlerExplainDTO.getCorpid())) {
            return handlerExplainVO;
        }
        // 开通过断点续传的白名单用户
        CompanyConfigEntity companyConfigEntity = companyConfigModel.getByConfigAlias(CompanyConfigEnum.UPLOAD_LIMIT_SIZE.getAlias(), handlerExplainDTO.getCorpid());
        boolean isUploadLimitWhite = Objects.nonNull(companyConfigEntity);
        List<FieldAttrEntity> headList = handlerExplainVO.getHeadList();
        for (FieldAttrEntity fieldAttr : headList) {
            // 选择产品字段SelectProductEnum
            if (ExplainUtil.isSubForm(fieldAttr.getFieldType())) {
                // 子表单字段处理
                List<? extends FieldAttrEntity> subHeadList = fieldAttr.getSubForm().getItems();
                for (FieldAttrEntity subFieldAttr : subHeadList) {
                    setExplainDefaultLimit(isUploadLimitWhite, subFieldAttr);
                }
                fieldAttr.getSubForm().setItems(subHeadList);
            } else {
                // 普通字段处理
                setExplainDefaultLimit(isUploadLimitWhite, fieldAttr);
            }
        }
        return handlerExplainVO;
    }

    /**
     * 为图片字段和附件字段设置限制默认值
     *
     * @param isUploadLimitWhite    是否开通过断点续传的白名单用户
     * @param fieldAttr             需要设置的对应字段
     */
    private void setExplainDefaultLimit(boolean isUploadLimitWhite, FieldAttrEntity fieldAttr) {
        if (Objects.equals(fieldAttr.getFieldType(), FieldTypeEnum.IMAGE.getType())) {
            if (Objects.isNull(fieldAttr.getLimitPicSize())) {
                fieldAttr.setLimitPicSize(EnableEnum.OPEN.getCode());
            }
            if (Objects.isNull(fieldAttr.getPicSize())) {
                fieldAttr.setPicSize(BasicConstant.IMAGE_MAX_SIZE_LIMIT);
            }
        } else if (Objects.equals(fieldAttr.getFieldType(), FieldTypeEnum.UPLOAD.getType())) {
            if (Objects.isNull(fieldAttr.getLimitFileSize())) {
                fieldAttr.setLimitFileSize(EnableEnum.OPEN.getCode());
            }
            if (Objects.isNull(fieldAttr.getFileSize())) {
                fieldAttr.setFileSize(isUploadLimitWhite ? BasicConstant.WHITE_UPLOAD_MAX_SIZE_LIMIT : BasicConstant.UPLOAD_MAX_SIZE_LIMIT);
            }
        }
    }

    /**
     * 设置字段的属性，回显用户名称，部门名称，角色名称，已经关联表的字段信息
     * @param entity 字段对象
     * @param userMap 用户容器
     * @param departmentMap 部门容器
     * @param roleMap 角色容器
     * @return 返回填充的字段信息
     * @throws XbbException 抛出业务异常
     */
    public FieldAttrEntity setFieldAttrEntity(FieldAttrEntity entity, HandlerExplainDTO handlerExplainDTO,Map<String, UserEntity> userMap,
                                              Map<String, DepartmentEntity> departmentMap, Map<String, RoleEntity> roleMap) throws XbbException{
        try {
            if (Objects.nonNull(entity.getDefaultAttr())) {
                List<OptionalRangeEntity> defaultList = entity.getDefaultAttr().getDefaultList();
                if(defaultList != null && !defaultList.isEmpty()){
                    defaultList = formDataFormExplainHelper.handleOptionalRangeList(defaultList,handlerExplainDTO.getCorpid(), userMap, departmentMap, roleMap);
                    entity.getDefaultAttr().setDefaultList(defaultList);
                }
            }
            LinkInfoPojo linkInfoPojo = entity.getLinkInfo();
            if(linkInfoPojo != null){
                Long linkFormId = linkInfoPojo.getLinkFormId();
                if (Objects.isNull(linkFormId)) {
                    // 返回没有配置关联表的关联数据和关联查询的字段
                    return entity;
                }

            }
            // 可编辑，添加编辑权限(同简道云：新建/编辑数据都使用些字段值，如有需要再修改)
            Integer editable = entity.getEditable() != null ? entity.getEditable() : BasicConstant.NO_USE;
            if(Objects.equals(BasicConstant.IS_USE, editable)) {
                Integer editAdvance = entity.getEditableAdvanceEnable();
                if(Objects.equals(BasicConstant.IS_USE, editAdvance)) {
                    VisibleRulePoJo editRulePojo = entity.getEditableRule();
                    if(editRulePojo != null) {
                        Integer editType = editRulePojo.getType();
                        VisibleTypeEnum editTypeEnum = VisibleTypeEnum.getByType(editType);
                        switch (editTypeEnum) {
                            case NOT_SHOW_ANYONE:
                                if(ExplainUtil.notShowAnyOne(editRulePojo, handlerExplainDTO)) {
                                    editable = BasicConstant.NO_USE;
                                }
                                break;
                            case SOME_PEOPLE_CAN_SEE:
                                if(ExplainUtil.fieldCanSee(editRulePojo, handlerExplainDTO)) {
                                    editable = BasicConstant.NO_USE;
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            entity.setEditable(editable);
        }catch (Exception e){
            LOG.error("AbstractFormExplainHandleName.setFieldAttrEntity：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return entity;
    }

    private LinkedAttrPoJo getLinkedAttr(LinkedAttrPoJo item, Map<String, FieldAttrEntity> explainMap) {
        FieldAttrEntity fieldAttrEntity = explainMap.get(item.getAttr());
        if(fieldAttrEntity == null){
            return null;
        }
        List<? extends FieldAttrEntity> subFieldList = new ArrayList<>();
        if (ExplainUtil.isSubForm(item.getFieldType()) && Objects.nonNull(item.getSubForm())) {
            subFieldList = item.getSubForm().getItems();
        }
        // 关联列表的显示字段名称不变，其他属性值，按照最新的变化
        String name = item.getAttrName();
        Integer fieldType = item.getFieldType();
        BeanUtil.copyProperties(fieldAttrEntity, item);
        item.setAttrName(name);
        item.setFieldType(fieldType);
        if (ExplainUtil.isSubForm(item.getFieldType()) && Objects.nonNull(item.getSubForm())) {
            item.getSubForm().setItems(subFieldList);
        }
        return item;
    }

    /**
     * 设置子表单字段属性
     * @param entity
     * @param userMap
     * @param departmentMap
     * @param roleMap
     * @return
     * @throws XbbException
     */
    public FieldAttrEntity setSubFieldAttrEntity(FieldAttrEntity entity, HandlerExplainDTO handlerExplainDTO, Map<String, UserEntity> userMap,
                                                 Map<String, DepartmentEntity> departmentMap, Map<String, RoleEntity> roleMap) throws XbbException{
        List<? extends FieldAttrEntity> subExplainList = entity.getSubForm().getItems();
        List<FieldAttrEntity> subFieldAttrList = new ArrayList<>();
        try {
            if(subExplainList == null){
                entity.getSubForm().setItems(new ArrayList<>());
                return entity;
            }
            Map<String, FieldPermissionEntityExt> permissionMap = handlerExplainDTO.getPermissionMap();
            // 普通表单高级可见规则
            if(Objects.isNull(permissionMap)) {
                if (ExplainUtil.invisibleOfScope(entity, handlerExplainDTO)) {
                    entity.setVisible(0);
                }
                if (!ExplainUtil.isEditableOfScope(entity, handlerExplainDTO)) {
                    entity.setEditable(0);
                }
            }
            for(FieldAttrEntity subFieldAttrEntity: subExplainList){
                // 字段回收站处理
                if (Objects.equals(subFieldAttrEntity.getIsOpen(), 2)) {
                    subFieldAttrEntity.setVisible(0);
                }

                if(Objects.isNull(permissionMap)) {
                    // 如果是表单的可编辑/可见权限
                    if (ExplainUtil.invisibleOfScope(subFieldAttrEntity, handlerExplainDTO)) {
                        subFieldAttrEntity.setVisible(0);
                    }
                    if (!ExplainUtil.isEditableOfScope(subFieldAttrEntity, handlerExplainDTO)) {
                        subFieldAttrEntity.setEditable(0);
                    }
                }

                subFieldAttrEntity = setFieldAttrEntity(subFieldAttrEntity, handlerExplainDTO, userMap, departmentMap, roleMap);
                // 流程权限读取
                if (Objects.nonNull(permissionMap)) {
                    String attr = entity.getAttr()+ StringConstant.POINT + subFieldAttrEntity.getAttr();
                    FieldPermissionEntityExt permissionEntity = permissionMap.get(attr);
                    if(permissionEntity == null){
                        continue;
                    } else {
                        if(permissionEntity.getVisible().equals(0)){
                            continue;
                        }
                        if(permissionEntity.getEditable().equals(1)){
                            subFieldAttrEntity.setEditable(1);
                        }else {
                            subFieldAttrEntity.setEditable(0);
                        }

                    }
                }
                // 套餐逻辑，标准版本隐藏复杂字段
                packageHelp.explainHide(handlerExplainDTO.getFeatureList(), subFieldAttrEntity);
                // 数据联动和联动其他表单
                packageHelp.setPackageLimit(handlerExplainDTO.getFeatureList(), subFieldAttrEntity);
                // 【高级/旗舰->标准】系统的正常使用，自定义公式不生效，设置部分不可用；
                packageHelp.limitFormula(handlerExplainDTO.getFeatureList(), subFieldAttrEntity, handlerExplainDTO.getBusinessType());
                subFieldAttrList.add(subFieldAttrEntity);
            }
            entity.getSubForm().setItems(subFieldAttrList);
        } catch (Exception e) {
            LOG.error("AbstractFormExplainHandleName.setFieldAttrEntity：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return entity;
    }

    /**
     * 渲染字段中的用户，部门，角色，并且根据表单过滤不可见字段
     * @param explainList
     * @return
     * @throws XbbException
     */
    public HandlerExplainVO getExplainList(List<FieldAttrEntity> explainList, HandlerExplainDTO handlerExplainDTO) throws XbbException{
        PaasFormEntityExt paasFormEntityExt = handlerExplainDTO.getPaasFormEntityExt();
        HandlerExplainVO handlerExplainVO = new HandlerExplainVO();
        //用户集合
        Map<String, UserEntity> userMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        //部门集合
        Map<String, DepartmentEntity> departmentMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        //角色集合
        Map<String, RoleEntity> roleMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<FieldAttrEntity> list = new ArrayList<>();
        List<String> featureList = packageHelp.getFeatureList(handlerExplainDTO.getCorpid());
        try {
            handlerExplainDTO.setFeatureList(featureList);
            //团队成员上线之后负责人唯一跟套餐相关了
            List<Integer> allBusinessList = FormOwnerUniqueEnum.getAllBusinessList();
            Integer feeType = commonHelp.getCurrentCompanyPackage(handlerExplainDTO.getCorpid());
            boolean teamOwnerUniqueTag = !Objects.equals(feeType, PackageTypeEnum.ULTIMATE.getType()) && allBusinessList.contains(handlerExplainDTO.getBusinessType());

            for (FieldAttrEntity entity: explainList) {
                // 允许可见，则处理以下规则
                List<VisibleRuleVO> userVoList = new ArrayList<>();
                if (Objects.equals(entity.getIsOpen(), 0)) {
                    // 非扩展字段，并且未开启时，字段不能显示在列表上
                    continue;
                }
                // 字段回收站处理
                if (Objects.equals(entity.getIsOpen(), 2)) {
                    entity.setVisible(0);
                }
                // 套餐逻辑，标准版本隐藏复杂字段
                packageHelp.explainHide(featureList, entity);
                // 套餐逻辑，数据联动和联动其他表单
                packageHelp.setPackageLimit(featureList, entity);
                // 限制公式
                packageHelp.limitFormula(featureList, entity, handlerExplainDTO.getBusinessType());
                // 高级可见规则回显用户名称
                if (ExplainUtil.invisibleOfScope(entity, handlerExplainDTO)) {
                    entity.setVisible(0);
                }
                if(ExplainUtil.isSubForm(entity.getFieldType())){
                    if (Objects.equals(entity.getFieldType(),FieldTypeEnum.SELECT_PRODUCT.getType())){
                        proFormHelp.setProductAccuracy(entity,handlerExplainDTO.getCorpid(), handlerExplainDTO.getUserId());
                    }
                    setSubFieldAttrEntity(entity, handlerExplainDTO, userMap, departmentMap, roleMap);
                }else{
                    setFieldAttrEntity(entity, handlerExplainDTO, userMap, departmentMap, roleMap);
                }
                if ( Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.CONTRACT.getCode()) ) {
                    if ( (Objects.equals(entity.getAttr(), ContractEnum.ADD_WRITE_OFF_PREPAYMENT.getAttr()) || Objects.equals(entity.getAttr(), ContractEnum.ADD_PAYMENT_SHEET.getAttr()))){
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAYMENT_SHEET_VIEW.getAlias()) ) {
                            entity.setVisible(0);
                        }
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAYMENT_SHEET_ADD.getAlias()) ) {
                            entity.setEditable(0);
                        }
                    } else if ( Objects.equals(entity.getAttr(), ContractEnum.ADD_PAYMENT.getAttr()) ) {
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAYMENT_VIEW.getAlias()) ) {
                            entity.setVisible(0);
                        }
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAYMENT_ADD.getAlias()) ) {
                            entity.setEditable(0);
                        }
                    }
                } else if ( Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.PURCHASE.getCode()) ) {
                    if ( (Objects.equals(entity.getAttr(), PurchaseEnum.ADD_WRITE_OFF_PREPAY.getAttr()) || Objects.equals(entity.getAttr(), PurchaseEnum.ADD_PAY_SHEET.getAttr()))){
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAY_SHEET_VIEW.getAlias()) ) {
                            entity.setVisible(0);
                        }
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAY_SHEET_ADD.getAlias()) ) {
                            entity.setEditable(0);
                        }
                    } else if ( Objects.equals(entity.getAttr(), PurchaseEnum.ADD_PAYPLAN.getAttr()) ) {
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAY_PLAN_VIEW.getAlias()) ) {
                            entity.setVisible(0);
                        }
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAY_PLAN_ADD.getAlias()) ) {
                            entity.setEditable(0);
                        }
                    }
                } else if ( Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.SUPPLIER.getCode()) ) {
                    if ( Objects.equals(entity.getAttr(), SupplierEnum.ADD_SUPPLIER_CONTACT.getAttr())){
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.SUPPLIER_CONTACT_VIEW.getAlias()) ) {
                            entity.setVisible(0);
                        }
                        if ( !handlerExplainDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.SUPPLIER_CONTACT_ADD.getAlias()) ) {
                            entity.setEditable(0);
                        }
                    }
                } else if (Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode())){
                    if (Objects.equals(entity.getAttr(), CustomerManagementEnum.CLUE_ID.getAttr())){
                        entity.setEditable(0);
                    }
                    if (!Objects.equals(handlerExplainDTO.getSubBusinessType(), XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode())) {
                        if (Objects.equals(entity.getAttr(), CustomerManagementEnum.OWNER_ID.getAttr())) {
                            //隔离模式下详情页负责人、协同人字段需要隐藏
                            boolean formShareTag = userTeamHelp.getFormShareTag(handlerExplainDTO.getCorpid(), paasFormEntityExt.getId(), paasFormEntityExt.getBusinessType());
                            if (!formShareTag) {
                                entity.setVisible(BasicConstant.ZERO);
                            }
                        }else if (Objects.equals(entity.getAttr(), CustomerManagementEnum.COUSERID.getAttr())) {
                            //隔离模式下详情页负责人、协同人字段需要隐藏
                            boolean formShareTag = userTeamHelp.getFormShareTag(handlerExplainDTO.getCorpid(), paasFormEntityExt.getId(), paasFormEntityExt.getBusinessType());
                            if (!formShareTag) {
                                entity.setVisible(BasicConstant.ZERO);
                            }
                        }
                    }
                } else if (Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.CLUE.getCode())) {
                    if (!Objects.equals(handlerExplainDTO.getSubBusinessType(), XbbRefTypeEnum.CLUE_PUBLIC.getCode())) {
                        if (Objects.equals(entity.getAttr(), ClueEnum.OWNER_ID.getAttr())) {
                            //隔离模式下详情页负责人、协同人字段需要隐藏
                            boolean formShareTag = userTeamHelp.getFormShareTag(handlerExplainDTO.getCorpid(), paasFormEntityExt.getId(), paasFormEntityExt.getBusinessType());
                            if (!formShareTag) {
                                entity.setVisible(BasicConstant.ZERO);
                            }
                        }else if (Objects.equals(entity.getAttr(), ClueEnum.COUSERID.getAttr())) {
                            //隔离模式下详情页负责人、协同人字段需要隐藏
                            boolean formShareTag = userTeamHelp.getFormShareTag(handlerExplainDTO.getCorpid(), paasFormEntityExt.getId(), paasFormEntityExt.getBusinessType());
                            if (!formShareTag) {
                                entity.setVisible(BasicConstant.ZERO);
                            }
                        }
                    }

                }else if (Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.RED_RECEIVABLES.getCode())) {
                    if (Objects.equals(entity.getAttr(), PaymentEnum.ADD_PAYMENT.getAttr())) {
                        entity.setVisible(BasicConstant.ZERO);
                    }
                } else if (Objects.equals(entity.getFieldType(), FieldTypeEnum.STAGE_THRUSTER.getType())) {
                    entity.setEditable(BasicConstant.ZERO);
                }

                //处理电话字段
                telephoneNumberMask(entity, handlerExplainDTO.getLoginUser());

                if (Objects.equals(handlerExplainDTO.getBusinessType(), XbbRefTypeEnum.COST_ADJUST.getCode())
                        && Objects.equals(entity.getAttr(), CostAdjustEnum.PRODUCT.getAttr())) {
                    List<? extends FieldAttrEntity> items = entity.getSubForm().getItems();
                    List<String> updataInvisibleAttrList = CostAdjustProductEnum.getUpdataInvisibleAttrList();
                    for (FieldAttrEntity item : items) {
                        if (updataInvisibleAttrList.contains(item.getAttr())) {
                            item.setVisible(0);
                        }
                    }
                }
                if (Objects.nonNull(entity.getVisibleScopeRule())){
                    entity.getVisibleScopeRule().setUserList(userVoList);
                }

                if (teamOwnerUniqueTag && Objects.equals(FieldTypeEnum.OWNERID.getAlias(), entity.getAttr())) {
                    entity.setMultiple(FormOwnerUniqueEnum.getFormOwnerUniqueByBus(handlerExplainDTO.getBusinessType()).getValue());
                }

                entity.setItems(proFormHelp.setItem(entity, paasFormEntityExt, handlerExplainDTO.getFormData()));
                list.add(entity);
            }
            handlerExplainVO.setUserMap(userMap);
            handlerExplainVO.setDepartmentMap(departmentMap);
            handlerExplainVO.setHeadList(list);
        }catch (XbbException e) {
            throw e;
        }catch (Exception e) {
            LOG.error("FormDataFormExplainHandleName.getExplainList处理字段中的部门、角色、用户等名称报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return handlerExplainVO;
    }

    /**
     * 只有编辑页会重写这个方法
     * @param fieldAttrEntity
     */
    protected void telephoneNumberMask(FieldAttrEntity fieldAttrEntity, UserVO loginUser) {

    }
}
